# try:
#     print("以读的方式打开")
#     open("test.txt","r")
#
# except:
#     print("以写的方式创建")
#     open("test.txt", "w")

#捕获指定异常
# try:
#     1/0
# except NameError:
#     print("cuowu")

#捕获多个指定异常
# try:
#     print(n)
#
# except (NameError,ZeroDivisionError):
#     print("报错了")
#
# #捕获多个指定异常
# try:
#     print(n)
#
# except NameError:
#     print("变量未定义")
# except ZeroDivisionError:
#     print("除数不为0")
#
# def fun():
#     try:
#         print("n")
#         1/0
#
#     except NameError as msg:
#         print(msg)
#     except ZeroDivisionError as msg:
#         print(msg)
#     #未捕获到异常出发else 里面的代码
#     else:
#         print("没有bug,开心啊")
#     #无论有无异常都要触发的代码
#     finally:
#         print("我是有无异常都要走的code")
#
# fun()


#异常的传递

try:
    print("代码。。。")
    try:
        1/0
        print(m)
    except NameError as msg:
        print(f"变量未定义")

except Exception as msg:
    print(f"报错信息:{msg}")
    raise